package com.lanyan.system.controller.system;

import java.math.BigDecimal;
import java.util.List;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lanyan.common.annotation.Log;
import com.lanyan.common.core.controller.BaseController;
import com.lanyan.common.core.domain.AjaxResult;
import com.lanyan.common.enums.BusinessType;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import com.lanyan.system.domain.SkuValue;
import com.lanyan.system.service.ISkuValueService;
import com.lanyan.common.utils.poi.ExcelUtil;
import com.lanyan.common.core.page.TableDataInfo;

/**
 * 规格值Controller
 *
 * @author lanyan
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/system/skuValue")
public class SkuValueController extends BaseController
{
    @Autowired
    private ISkuValueService skuValueService;

    /**
     * 查询规格值列表
     */
    @PreAuthorize("@ss.hasPermi('system:skuValue:list')")
    @GetMapping("/list")
    @ApiImplicitParams({
          @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
          @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
          @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "productId", value = "所属商品", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "skuNameId", value = "所属规格名", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "value", value = "规格值", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "pageNum", value = "第几页", dataType = "int", dataTypeClass = int.class),
          @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", dataTypeClass = int.class),

    })
    public TableDataInfo list(SkuValue skuValue)
    {
        startPage();
        List<SkuValue> list = skuValueService.selectSkuValueList(skuValue);
        return getDataTable(list);
    }

    /**
     * 导出规格值列表
     */
    @PreAuthorize("@ss.hasPermi('system:skuValue:export')")
    @Log(title = "规格值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SkuValue skuValue)
    {
        List<SkuValue> list = skuValueService.selectSkuValueList(skuValue);
        ExcelUtil<SkuValue> util = new ExcelUtil<SkuValue>(SkuValue.class);
        util.exportExcel(response, list, "规格值数据");
    }

    /**
     * 获取规格值详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:skuValue:query')")
    @GetMapping(value = "/{skuValueId}")
    public AjaxResult getInfo(@PathVariable("skuValueId") Long skuValueId)
    {
        return success(skuValueService.selectSkuValueBySkuValueId(skuValueId));
    }

    /**
     * 新增规格值
     */
    @PreAuthorize("@ss.hasPermi('system:skuValue:add')")
    @Log(title = "规格值", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "productId", value = "所属商品", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "skuNameId", value = "所属规格名", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "value", value = "规格值", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult add(@RequestBody SkuValue skuValue)
    {
        return toAjax(skuValueService.insertSkuValue(skuValue));
    }

    /**
     * 修改规格值
     */
    @PreAuthorize("@ss.hasPermi('system:skuValue:edit')")
    @Log(title = "规格值", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "productId", value = "所属商品", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "skuNameId", value = "所属规格名", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "value", value = "规格值", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult edit(@RequestBody SkuValue skuValue)
    {
        return toAjax(skuValueService.updateSkuValue(skuValue));
    }

    /**
     * 删除规格值
     */
    @PreAuthorize("@ss.hasPermi('system:skuValue:remove')")
    @Log(title = "规格值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{skuValueIds}")
    public AjaxResult remove(@PathVariable Long[] skuValueIds)
    {
        return toAjax(skuValueService.deleteSkuValueBySkuValueIds(skuValueIds));
    }
}
